package com.retail.proxy.controller;

import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;

import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.security.LoginUserUtil;
import com.retail.global.annon.TraceLog;
import com.retail.proxy.entity.request.ProxyMechanismRequest;
import com.retail.proxy.entity.vo.ProxyMechanismVo;
import com.retail.proxy.service.ProxyMechanismService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 代理机制 API
* @author Administrator
*/
@Api(tags = "代理机制 API")
@RestController
@RequestMapping("/proxyMechanism")
public class ProxyMechanismController extends AbstractCommonController<ProxyMechanismService, ProxyMechanismRequest, ProxyMechanismVo> {

    @Autowired
    private ProxyMechanismService proxyMechanismService;

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(proxyMechanismService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存代理机制")
    public Result<Integer> save(@RequestBody ProxyMechanismRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(proxyMechanismService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新代理机制")
    public Result<Integer> update(@RequestBody ProxyMechanismRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(proxyMechanismService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("代理机制-查询")
    public Result<List<ProxyMechanismVo>>listPage(@RequestBody ParamReq req) {
        return super.listPage(proxyMechanismService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("代理机制-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(proxyMechanismService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("代理机制-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<ProxyMechanismRequest> req) {
        return super.page(proxyMechanismService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除代理机制")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(proxyMechanismService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除代理机制")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(proxyMechanismService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
